/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.tukano.swingdeco.draganddrop;

import java.awt.Component;
import java.awt.datatransfer.DataFlavor;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetAdapter;
import java.awt.dnd.DropTargetDropEvent;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author utente4
 */
public abstract class DropTargetHandler extends DropTargetAdapter {
    
    private final boolean local;
    
    public DropTargetHandler(boolean local) {
        this.local = local;
    }
    
    public DropTargetHandler() {
        this(false);
    }
    
    public static void install(Component c, DropTargetAdapter t) {
        DropTarget target = new DropTarget(c, t);
    }

    public void drop(DropTargetDropEvent e) {
        try {
            if(local) {
                handleLocalDrop(e.getTransferable().getTransferData(new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType)));
            } else {
                handleDrop(e);
            }
        } catch (Throwable ex) {
            Logger.getLogger(DropTargetHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    protected void handleLocalDrop(Object data) throws Throwable {}
    
    protected void handleDrop(DropTargetDropEvent e) throws Throwable {}
}
